package com.cloud.mq.topic;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest
@RunWith(SpringRunner.class)
public class ProdcerTopicsSpringbootApplicationTests {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @Test
    public void Producer_topics_springbootTest() {

        /**
         * 参数：
         * 1、交换机名称
         * 2、routingKey
         * 3、消息内容
         */
        rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS, RabbitmqConfig.ROUTINGKEY_TRANSFER_MOVIE, String.format("来自队列名'%s'的报文1", RabbitmqConfig.QUEUE_TRANSFER_MOVIE));
        rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS, RabbitmqConfig.ROUTINGKEY_TRANSFER_MOVIE, String.format("来自队列名'%s'的报文2", RabbitmqConfig.QUEUE_TRANSFER_MOVIE));
        rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS, RabbitmqConfig.ROUTINGKEY_TRANSFER_MOVIE, String.format("来自队列名'%s'的报文3", RabbitmqConfig.QUEUE_TRANSFER_MOVIE));
        rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS, RabbitmqConfig.ROUTINGKEY_TRANSFER_MOVIE, String.format("来自队列名'%s'的报文4", RabbitmqConfig.QUEUE_TRANSFER_MOVIE));

    }


}
